import UserInfo from '@/components/frontPage/UserInfo'
import BasicAttributes from '@/components/frontPage/BasicAttributes'
import File from '@/components/frontPage/File'
import Bom from '@/components/frontPage/Bom'
import SortTable from '@/components/frontPage/SortTable'
import SortTableOperate from '@/views/frontPage/document/sortTableOperate'

import BasicInfo from '@/components/frontPage/BasicInfo'
import ChangeRecord from '@/components/frontPage/ChangeRecord'
import HistoricalRecord from '@/components/frontPage/HistoricalRecord'
import UseLocation from '@/components/frontPage/UseLocation'
import Relation from '@/components/frontPage/Relation'
import Tree from '@/views/frontPage/materials/components/tree'
import ReplaceMaterial from '@/views/frontPage/materials/components/ReplaceMaterial'
import DialogDelete from '@/views/frontPage/materials/components/DialogDelete'
import {
  // postQueryPageList,
  putUpdate
} from '@/api/frontPage/document/index'
export default {
  components: {
    ChangeRecord,
    HistoricalRecord,
    UseLocation,
    Relation,
    UserInfo,
    Tree,
    BasicAttributes,
    File,
    Bom,
    DialogDelete,
    ReplaceMaterial,
    SortTable,
    BasicInfo,
    SortTableOperate
  },
  data() {
    return {
      /*  */
      sortTableSelectVal: {},
      sortTableOperateVal: {},
      billmaterialsFrom: {
        materials: '1'
      },
      baIsEdit: true,
      baLoading: false,
      baFromData: [],
      options: [],
      mobileData: {},
      tabPaneList: [
        { label: '基本属性', name: '01' },
        { label: 'BOM', name: '02' },
        { label: '附件', name: '03' },
        { label: '关系', name: '04' },
        { label: '替代料', name: '05' },
        { label: '变更记录', name: '06' },
        { label: '使用位置', name: '07' },
        { label: '历史记录', name: '08' }
      ],
      fixedFieldVal: {}, // 基本属性的固定值
      tabName: '02',
      statusVal: '',
      stDropdownList: [
        {
          value: '01',
          label: '收藏',
          visible: false
        },
        {
          value: '02',
          label: '另存为',
          visible: false
        },
        {
          value: '03',
          label: '新建文件夹',
          visible: false
        },
        {
          value: '04',
          label: '新建变更',
          visible: false,
          children: [
            {
              value: '041',
              label: '变更申请'
            },
            {
              value: '042',
              label: '变更指令'
            }
          ]
        },
        {
          value: '05',
          label: '删除',
          visible: false
        },
        {
          value: '06',
          label: '复制',
          visible: false
        },
        {
          value: '07',
          label: '打印',
          visible: false
        },
        {
          value: '08',
          label: '导出',
          visible: false
        }
      ],
      stTableData: [],
      stTableColumn: [
        { field: 'icon', width: '30' },
        { field: 'name', title: '编号', showOverflow: true, treeNode: true },
        { field: 'desc', title: '描述', showOverflow: true }
      ],
      tTreeData: [],
      tLoading: false
    }
  },
  computed: {

  },
  created() {
    // this.initBasicAttributes()
    // this.initTabPane()
  },
  methods: {
    /* MaterIals page */
    isPage() { return this.$route.name === 'Materials' },

    biStatusChange(val) {
      this.statusVal = val
    },
    biHandleBasicInfo(val) {
      this.fixedFieldVal = {
        description: val.description,
        unit: val.unit
      }
    },
    tabClick(val) {
      switch (val.name) {
        case '01':
          // 基本属性
          this.baIsEdit = true
          this.initBasicAttributes()
          break
        case '02':
          // 附件
          break
        case '03':
          // 关系
          break
        case '04':
          // 变更记录
          break
        case '05':
          // 使用位置
          break
        case '06':
          // 历史记录
          break
      }
    },
    baHandleSave(val) {
      this.baIsEdit = true
    },
    baHandleCancel() {
      this.baIsEdit = true
      this.initBasicAttributes()
    },
    baHandleEdit() {
      this.baIsEdit = false
    },
    initBasicAttributes() {
      this.baFromData = []
      this.baLoading = true
      setTimeout(() => {
        this.baLoading = false
        this.baFromData = [
          {
            label: '名称',
            name: 'name',
            type: 'input',
            value: '',
            props: {
              type: 'input',
              placeholder: '请输入名称',
              maxlength: 10,
              clearable: true
            },
            validate: [
              { required: true, message: '请输入名称', trigger: 'blur' }
            ]
          },
          {
            label: '日期',
            name: 'dateTime',
            type: 'date',
            value: '2020-07-14',
            props: {
              type: 'date',
              placeholder: '选择日期',
              valueFormat: 'yyyy-MM-dd'
            }
          },
          {
            name: 'status',
            type: 'select',
            label: '状态',
            value: '1',
            props: {
              type: 'input',
              placeholder: '请选择'
            },
            options: [
              { value: '0', label: '禁用' },
              { value: '1', label: '启用' }
            ]
          },
          {
            name: 'radioVal',
            type: 'radio',
            label: '类型',
            value: '1',
            props: {},
            options: [
              { value: '0', label: '品牌商赞助' },
              { value: '1', label: '场地免费' }
            ]
          },
          {
            name: 'ziyuan',
            type: 'checkbox',
            label: '特殊资源',
            value: ['1'],
            props: {},
            options: [
              { value: '0', label: '上海' },
              { value: '1', label: '北京' },
              { value: '2', label: '广州' },
              { value: '3', label: '深圳' }
            ]
          },
          {
            name: 'remark',
            isRows: true,
            type: 'input',
            label: '描述',
            value: '2',
            props: {
              type: 'textarea',
              placeholder: '请输入文本域',
              autosize: { minRows: 3 }
            }
          },
          {
            name: 'isPeiSong',
            type: 'switch',
            label: '即时配送',
            value: true
          }
        ]
      }, 1000)
    },

    // 文件类型数据禁止移入
    tAllowDrop(draggingNode, dropNode, type) {
      return false
    },
    // 拖拽数据
    tNodeDrop(selfNode, dropNode, dropType) {
    // after:移到节点下面  inner:移到节点里面  before: 移到节点上面
      const params = {
        id: selfNode.data.id,
        updateType: selfNode.data.objectType
      }
      // console.log(dropType, selfNode, dropNode.level)
      if (dropType === 'inner') {
        params.parentFileId = dropNode.data.id
      // console.log(dropNode.data.name, '新的父节点')
      } else {
        if (dropNode.level === 1) {
          params.parentFileId = ''
        // console.log('新的父节点为空')
        } else {
          params.parentFileId = dropNode.parent.data.id
        // console.log(dropNode.parent.data.name, '新的父节点')
        }
      }
      putUpdate(params).then(res => {
        const treeSelectVal = JSON.parse(JSON.stringify(this.treeSelectVal))
        this.tCurrentChange(treeSelectVal)
      }).catch(() => {
        this.queryData(this.sortTableOperateVal)
      })
    },
    tHandleDragStart(node, ev) {
      this.mobileData = node.data
    },
    stNewResult(val) {
      console.log(val)
      const params = {
        id: val.selfVal.id,
        parentFileId: val.newParent ? val.newParent.id : '',
        updateType: val.selfVal.objectType
      }
      putUpdate(params).then(res => {
        console.log(res, '拖拽')
      }).catch(() => {
        this.$message.error('拖拽失败！！！')
        this.queryData(this.sortTableOperateVal)
      })
    },
    // 左边 选中高亮数据
    stCellClick(val) {
      // 防止重复触发数据
      if (val.id === this.sortTableSelectVal.id) {
        return
      }
      this.sortTableSelectVal = val
    }

  }
}
